package com.morningstar.common.message;

import cn.hutool.extra.template.Template;
import cn.hutool.extra.template.TemplateConfig;
import cn.hutool.extra.template.TemplateEngine;
import cn.hutool.extra.template.TemplateUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.Map;

/**
 * 系统消息
 *
 * @author Admin
 */
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class BaseMessage {

    /**
     * 消息标题
     */
    private String title;

    /**
     * 目标用户
     */
    private Long targetUserId;

    /**
     * 消息模板key
     */
    private String templateKey;

    /**
     * 消息参数
     */
    private Map<String, String> params;

    public String getMessageContent(String templateStr) {
        TemplateEngine engine = TemplateUtil.createEngine(new TemplateConfig());
        Template template = engine.getTemplate(templateStr);
        return template.render(this.getParams());
    }
}
